package com.acme.bankapp.domine.account;

import com.acme.bankapp.exceptions.OverDraftLimitExceededException;

public class CheckingAccount extends AbstractAccount {
    private double overdraft;

    public double getOverdraft() {
        return overdraft;
    }

    public CheckingAccount(final int id, final double amount,
            final double overdraft) throws IllegalArgumentException {
        super(id, amount);
        setType("CheckingAccount");
        if (overdraft < 0) {
            throw new IllegalArgumentException("CheckingAccount: "
                    + "Overdraft can not be negative");
        }
        this.overdraft = overdraft;
    }

    @Override
    public void withdraw(final double amount)
            throws OverDraftLimitExceededException {
        if (getBalance() + overdraft >= amount) {
            setBalance(getBalance() - amount);
        } else {
            throw new OverDraftLimitExceededException("CheckingAccount: "
                    + "Amount withdraw can not be negative");
        }
    }

    @Override
    public double maximumAmountToWithdraw() {
        return getBalance() + overdraft;
    }
}
